package validators;

import java.util.ResourceBundle;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;


@FacesValidator("validators.DomainValidator")
public class DomainValidator implements Validator {
	
	ResourceBundle bundle = ResourceBundle.getBundle(
			"languageSettings.language", FacesContext.getCurrentInstance()
					.getViewRoot().getLocale());
	
	public DomainValidator(){
		
	}
	
	@Override
	public void validate(FacesContext context, UIComponent component,
			Object value) throws ValidatorException {
		if (((String)value).length() < 2 || ((String)value).length() > 32 ){
			FacesMessage mes = new FacesMessage(bundle.getString("Validators_DomainValidator_Error"));
			mes.setSeverity(FacesMessage.SEVERITY_ERROR);
			throw new ValidatorException(mes);
		}
		
	}

}
